// 使用 String.Index 进行索引

// 获取索引
let str = "Hello, World!"
let firstIndex: String.Index = str.startIndex
let sencondIndex = str.index(after: firstIndex)
print(str[sencondIndex])

// 获取子串
let str1 = "Hello, World!"
let commaIndex: String.Index = str1.firstIndex(of: ",")!
let subString = str1[..<commaIndex]
print(subString)

// 子串操作
// prefix(_:)：获取前缀子串
let str2 = "Hello, World!"
let prefix = str2.prefix(5)
print(prefix)  // 输出：Hello
